package com.smartcommunity.job;

import com.smartcommunity.entity.village.SixEntity;
import com.smartcommunity.service.sixEntity.SixEntityService;
import com.smartcommunity.service.sixEntity.StatisticsService;
import com.smartcommunity.utils.ToolDateTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author heweiwei
 * @date 2018/7/11
 * 定时统计小区一标六实统计表
 */
@Component
@Slf4j
public class SixEntityJob {

    private final StatisticsService statisticsService;
    private final SixEntityService sixEntityService;

    /**
     * 统计任务是否正在运行
     */
    private static Boolean isRunSense = false;

    @Autowired
    public SixEntityJob(StatisticsService statisticsService,SixEntityService sixEntityService) {
        this.statisticsService = statisticsService;
        this.sixEntityService = sixEntityService;
    }

    /**
     * 定时轮询一次
     */
    @Scheduled(initialDelay = 10 * 1000, fixedDelay = 2 * 60 * 1000)
    public void sixEntityScheduled() {
        Date d = new Date();
        log.info("一标六实统计定时任务开始");
        try {
            statisticsService.statisticsSixEntity();
        } catch (Exception e) {
            log.error("一标六实统计错误", e);
        } finally {
            //标记任务结束
            log.info("一标六实统计定时任务结束，耗时："+ ToolDateTime.getDiffTime(d) + "毫秒");
        }
    }

}
